#pragma once

#include <QFrame>
#include <QMap>
#include <QPair>
#include <QTimer>
#include <QVector>

class QHBoxLayout;
class AppMenuCategoryPanel;
class AppMenuCommentsPanel;
class SImage;

struct MenuComments {
  QString title;
  QVector<QPair<QString, QColor>> comments;
};

class AppMenuPanel : public QFrame {
  Q_OBJECT
 public:
  AppMenuPanel(QWidget* parent);

  static AppMenuPanel* g_menuPanel() { return s_menu; };

  void onItemHoverChanged(int id, bool hovered);
  void onItemAction(int id, bool addToFav);
  void setFavPanel(AppMenuCategoryPanel* panel);
  bool canAddToFav() const;
  bool hasAddedToFav(int cmdId) const;
 public slots:
  void onCommonPage(int* ids, int size, int ntype);

 protected:
  void paintEvent(QPaintEvent* event) override;
  void mouseMoveEvent(QMouseEvent* event) override;
  void timerEvent(QTimerEvent* event) override;

 protected:
  void onTimerOut();

 private:
  void construct();
  void loadMenuComments();
  void switchMenu(int index);
  void initRedPointLabel();

  void killAnimateTimer();
  void killSwitchTimer();

 private:
  QVector<QPair<int, QString>> m_firstLabels;
  QVector<QRect> m_rects;
  QTimer m_timer;
  int m_activeMenu = -1;
  int m_hoverMenu = -1;
  int m_timerSwitch = -1;
  int m_timerAnimate = -1;
  QHBoxLayout* m_mainLayout = nullptr;
  QVector<QVector<AppMenuCategoryPanel*>> m_categories;
  AppMenuCategoryPanel* m_FavPanel = nullptr;
  QMap<int, MenuComments> m_menuComments;
  AppMenuCommentsPanel* m_commentsPanel = nullptr;
  static AppMenuPanel* s_menu;
  QVector<QPair<int, bool>> m_redLabel;
  SImage* m_imgLogo;
};